#include <sys/types.h>
#include <sys/socket.h>
#include <iostream>
#include <string>
#include <strings.h>
#include <netinet/in.h>
#include <arpa/inet.h>

const int def_fd = -1;

class server
{
public:
    server(const std::string ip, uint16_t port)
        :_fd(def_fd)
        ,_ip(ip)
        ,_port(port)
    {
    }

    void init()
    {
        // 1、创建套接字
        _fd = socket(AF_INET, SOCK_DGRAM, 0);
        if (_fd != 0)
        {
            std::cout << "套接字创建失败" << std::endl;
        }
        std::cout << "套接字创建成功" << std::endl;
        // 2、创建套接字信息，ip和端口
        struct sockaddr_in local;
        bzero(&local, sizeof(local));
        local.sin_family = AF_INET;
        local.sin_port = htons(_port);
    }

private:
    int _fd;
    const std::string _ip;
    uint16_t _port;
};